package com.thesis.object;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * ListBillDescription class
 * 
 * save many list bill description
 * 
 * @author NgocTuyen
 *
 */
public class ListBillDescription {
	//array list of many bills
	private ArrayList<BillDescription> listBillDescription;
	
	/**
	 * Constructor function
	 * 
	 * Constructor
	 * 
	 * @access public 
	 * 
	 * @param null
	 * 
	 * @return null
	 */
	public ListBillDescription(){
		listBillDescription = new ArrayList<BillDescription>();
	}
	
	/**
	 * addBillDescriptionByJson function
	 * 
	 * add all bill desciption into list bills description
	 * 
	 * @access public
	 * 
	 * @param listJson: list of many bills description
	 * 
	 * @return void
	 */
	public void addBillDescriptionByJson(JSONArray listJson){
		for (int i = 0; i < listJson.length(); i++) {
			try {
				addBillDescription(listJson.getJSONObject(i));
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * addBillDescription function
	 * 
	 * add a bill description into list bill description
	 * 
	 * @access private
	 * 
	 * @param jsonObj: json of one bill description
	 * 
	 * @return void
	 */
	private void addBillDescription(JSONObject jsonObj){
		try {
			//TODO asdsdas
			BillDescription billDescription = new BillDescription(jsonObj.getInt("_id"), jsonObj.getInt("bill_id"), jsonObj.getInt("food_id"), /*jsonObj.getString("name")*/"aaaa", jsonObj.getInt("number"), jsonObj.getString("food_note"), jsonObj.getString("date"), jsonObj.getString("start_time"), jsonObj.getString("serve_time"), jsonObj.getInt("cost"), jsonObj.getString("description"), jsonObj.getString("feedback"));
			listBillDescription.add(billDescription);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * getListBill function
	 * 
	 * get list of many bills description
	 * 
	 * @access public
	 * 
	 * @param null
	 * 
	 * @return ArrayList<BillDescription>
	 *  + list of bill description
	 */
	public ArrayList<BillDescription> getListBill(){
		return listBillDescription;
	}
}
